export const TENANT_ID = 'cms-tenantId';
export const USER_INFO = 'cms-userInfo';
export const ACCESS_TOKEN = 'cms-access-token';
export const REFRESH_TOKEN = 'cms-refresh-token';
export const ALL_MENU = 'cms-allMenu';

export const parseKey = (key: string) => {
  const path = ''; // location.pathname.split('/')[1];
  return `${path}-${key}`;
};

export const setItem = (key: string, value: any) => {
  const path = parseKey(key);
  localStorage.setItem(path, JSON.stringify(value));
};

export const removeItem = (key: string) => {
  const path = parseKey(key);
  localStorage.removeItem(path);
};

export const getItem = (key: string) => {
  const path = parseKey(key);
  try {
    return JSON.parse(localStorage.getItem(path) as string);
  } catch (e) {
    console.error(e);
    return null;
  }
};
